package com.sys.web.head.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sys.common.controller.BaseController;
import com.sys.common.pojo.ApiResponse;
import com.sys.common.util.ConstatFinalUtil;
import com.sys.common.util.PageInfoUtil;
import com.sys.users.pojo.ScenicSpot;
import com.sys.users.service.IUsersDbService;

/**
 * 不需要登陆的Controller
 * 
 * @author 梦缠绵
 */
@Controller
public class IndexHeadController extends BaseController
{
	@Resource
	private IUsersDbService usersDbService;
	
	/**
	 * 首页
	 * @return
	 */
	@RequestMapping("/main")
	public String main()
	{
		ConstatFinalUtil.SYS_LOGGER.info("====main====");
		return "/head/main";
	}
	
	/**
	 * 景点列表
	 * @return
	 */
	@RequestMapping("/scenicspotList")
	public String scenicspotList(HttpServletRequest request,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("====scenicspotList====");
		/* 分页信息 */
		PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);
		/* 搜索条件,生成公共的搜索条件 */
		Map<String, Object> condMap = this.proccedSearch(request);
		/* -- 城市开始 -- */
		String city = request.getParameter("city");
		if(city == null)
		{
			city = "" ; 
		}
		condMap.put("city", city);
		request.setAttribute("city", city);
		/* -- 城市结束 -- */
		/*
		 * 查询数据库 所有的数据以JSON的形式返回
		 */
		ApiResponse<ScenicSpot> response = this.usersDbService.findCondListScenicSpotService(pageInfoUtil, condMap);
		/* 将结果存储到Request中 */
		model.addAttribute("response", response.toJSON());
		return "/head/scenicspotList";
	}
	
	/**
	 * 景点详情
	 * @return
	 */
	@RequestMapping("/scenicspotInfo")
	public String scenicspotInfo(HttpServletRequest request,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("====scenicspotInfo====");
		String id = request.getParameter("id");
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<ScenicSpot> response = this.usersDbService.findOneScenicSpotService(condMap);
		/* 存储request */
		model.addAttribute("response", response.toJSON());
		/* 操作类型 */
		String operType = request.getParameter("operType");
		return "/head/scenicspotInfo";
	}
}
